local skel = fk.CreateSkill {
  name = "emo__qingyang",
}

Fk:loadTranslationTable{
  ["emo__qingyang"] = "轻扬",
  [":emo__qingyang"] = "你获得过牌的阶段结束时，你可以展示本阶段获得的牌，若如此做，你获得牌堆中非来自标准包的一张牌。",

  ["#emo__qingyang-show"] = "轻扬：你可以展示本阶段获得的牌",
}

skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and player == target and not player:isKongcheng() then
      local cards = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.to == player and move.toArea == Player.Hand then
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
        return false
      end, Player.HistoryPhase)
      cards = table.filter(cards, function(id) return table.contains(player:getCardIds("h"), id) end)
      if #cards > 0 then
        event:setCostData(self, cards)
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = event:getCostData(self)
    return cards and player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__qingyang-show"})
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self)
    player:showCards(cards)
    if player.dead then return false end
    local pile = table.simpleClone(room.draw_pile)
    while #pile > 0 do
      local id = table.remove(pile, math.random(1, #pile))
      local card = Fk:getCardById(id)
      if card.package and card.package.name ~= "standard_cards" then
        room:moveCardTo(card, Player.Hand, player, fk.ReasonPrey, skel.name)
        return
      end
    end
  end,
})

return skel
